package android.tong;

import java.util.ArrayList;
import java.util.Map;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

public class MenuList2 extends Activity {

	private ListView lv;
	private TextView tv;
	private DataModel2 dm;
	private ArrayList<Map<String, Object>> coll;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list);
		dm = new DataModel2();
		lv = (ListView)findViewById(R.id.list);
		lv.setOnItemClickListener(listener);
		tv = (TextView)findViewById(R.id.TextView01);
		
		coll = dm.loadData();
		SimpleAdapter adapter = new SimpleAdapter(this, coll, android.R.layout.simple_list_item_1, 
				new String[] {"prod_na"}, new int[] {android.R.id.text1});
		lv.setAdapter(adapter);
		
	}	
	
	OnItemClickListener listener = new OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
			// TODO Auto-generated method stub
			tv.setTextColor(Color.YELLOW);
			tv.setText(coll.get(arg2).get("prod_type").toString());
		}
		
	};
}
